// 运行时配置
import { setting } from '../config/layout';
import { RightContent } from './layouts/rightContent';

// 全局初始化数据配置，用于 Layout 用户信息和权限初始化
// 更多信息见文档：https://umijs.org/docs/api/runtime-config#getinitialstate
export async function getInitialState(): Promise<{ name: string }> {
  return { name: '@umijs/max' };
}

export const layout = () => {
  return {
    ...setting,
    title: 'umi-max模板',
    logo: 'https://img.alicdn.com/tfs/TB1YHEpwUT1gK0jSZFhXXaAtVXa-28-27.svg',
    menu: {
      locale: false,
    },
    rightContentRender: RightContent,
  };
};

// 仅在开发环境下运行，用于去除控制台误打印
if (process.env.NODE_ENV === 'development') {
  console.error = new Proxy(console.error, {
    apply(target, thisArg, args) {
      const firstArg = args[0];
      if (
        typeof firstArg === 'string' &&
        firstArg.includes('Warning: findDOMNode is deprecated')
      ) {
        return; // 忽略特定警告
      }
      return Reflect.apply(target, thisArg, args); // ✅ 保留原始调用栈
    },
  });
}
